package com.sh.data.engine.domain.normalization.standard.model.domain;

import com.sh.data.engine.repository.dao.normalization.standard.entity.DictionaryEntity;
import lombok.Builder;
import lombok.Data;

import java.util.List;

import static java.lang.Math.toIntExact;

/**
 * @Version 1.0 @Author:xinyan @Date:2022/7/26 @Content:
 */
@Data
@Builder(toBuilder = true)
public class DictionaryPublishDomain {

    private Integer dictionarieTotal;

    private Integer publish;

    private Integer disPublish;

    public static DictionaryPublishDomain getDicStatistics(List<DictionaryEntity> list) {

        return DictionaryPublishDomain.builder()
            .dictionarieTotal(toIntExact(list.size()))
            .publish(toIntExact(list.stream().filter(DictionaryEntity::isRelased).count()))
            .disPublish(toIntExact(list.stream().filter(DictionaryEntity::disRelased).count()))
            .build();
    }

    public static DictionaryPublishDomain newStatDomain(List<DictionaryEntity> dic) {

        return DictionaryPublishDomain.getDicStatistics(dic);
    }
}
